package cp5_jdbc.servlet;

import util.StringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/cp5/login-success")
public class LoginSuccessServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession sess = req.getSession();// 获取session
        PrintWriter out = StringUtil.getWriter(resp);//获取输出对象
        if(sess.getAttribute("login_username") == null){
            out.println("请先登录");
            out.println("<script>setTimeout(()=>{history.back();},3000);</script>");
        }else{
            out.println("登录成功");
            out.println("账号:" + sess.getAttribute("login_username"));
            out.println("昵称:" + sess.getAttribute("login_user_nickname"));
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
